package com.bcqn.controller;

import com.bcqn.common.CommonResponse;
import com.bcqn.model.Post;
import com.bcqn.service.PostService;
import com.bcqn.vo.PostQueryVo;
import com.bcqn.vo.PostVo;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * PostController
 *
 * @author Kelly
 * @version v1.0
 * @date 2020/4/17 20:43
 */
@RestController
@RequestMapping("/post")
@Slf4j
public class PostController {

    @Autowired
    private PostService postService;

    /**
     * 根据id查询帖子信息
     * @param
     * @return
     */
    @GetMapping("/getById")
    public CommonResponse getById(@RequestParam Long id,@RequestParam Long userId) {
        return CommonResponse.success(postService.getById(id,userId));
    }


    /**
     * 查询热门帖子列表
     * @param postQueryVo
     * @return
     */
    @GetMapping("/getHotPostList")
    public CommonResponse getHotPostList(PostQueryVo postQueryVo) {
        PageInfo<PostVo> hotPostList = postService.getHotPostList(postQueryVo);
        return CommonResponse.success(hotPostList);
    }

    /**
     * 查询热门帖子列表/根据userId查询帖子
     * @param postQueryVo
     * @return
     */
    @GetMapping("/getLatestPostList")
    public CommonResponse getLatestPostList(PostQueryVo postQueryVo) {
        PageInfo<PostVo> latestPostList = postService.getLatestPostList(postQueryVo);
        return CommonResponse.success(latestPostList);
    }

    /**
     * 新增/修改帖子
     * @param post
     * @return
     */
    @PostMapping("/update")
    public CommonResponse update(@RequestBody Post post) {
        return CommonResponse.success(postService.update(post));
    }

    /**
     * 帖子点赞/取消点赞
     * @param postId
     * @param userId
     * @param likeStatus
     * @return
     */
    @PostMapping("/updateLike")
    public CommonResponse updateLike(@RequestParam Long postId, @RequestParam Long userId, @RequestParam Integer likeStatus) {
        return CommonResponse.success(postService.updateLike(postId,userId,likeStatus));
    }

    /**
     * 收藏/取消收藏帖子
     * @param postId
     * @param status
     * @return
     */
    @PostMapping("/collection")
    public CommonResponse collection(@RequestParam Long postId, @RequestParam Long userId, @RequestParam Integer status) {
        return CommonResponse.success(postService.collection(postId,userId,status));
    }

    @GetMapping("/myCollection")
    public CommonResponse myCollection(PostQueryVo postQueryVo) {
        return CommonResponse.success(postService.getMyCollection(postQueryVo));
    }

}
